package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CaseInfo;
import cn.wolfcode.crm.domain.CompensationInfo;
import cn.wolfcode.crm.query.CaseInfoQuery;
import cn.wolfcode.crm.service.ICaseInfoService;
import cn.wolfcode.crm.service.ICompensationInfoService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;

@Controller
@RequestMapping("/caseInfo")
public class CaseInfoController {
    @Autowired
    private ICaseInfoService caseInfoService;
    @Autowired
    private ICompensationInfoService compService;

    //理赔明细表
    @RequestMapping("/viewAudit")
    public String viewAudit() {
        return "compensate/audit";
    }

    @RequestMapping("/queryAudit")
    @ResponseBody
    public Object queryAudit(CaseInfoQuery qo) {
        qo.setStatus(Arrays.asList(CaseInfo.UNAUDIT));
        return caseInfoService.query(qo);
    }

    //====================================================================
    // 理赔明细表
    @RequestMapping("/viewDetail")
    public String viewDetail() {
        return "compensate/detail";
    }

    // 理赔明细显示的内容
    @RequestMapping("/queryDetail")
    @ResponseBody
    public Object queryDetail(CaseInfoQuery qo) {
        qo.setStatus(Arrays.asList(CaseInfo.VERITY, CaseInfo.REJECT_AUDIT));
        return caseInfoService.query(qo);
    }

    @RequestMapping("/selectCompensationInfoById")
    @ResponseBody
    public Object selectCompensationInfoById(Long compensationInfoId) {
        return caseInfoService.selectCompensationInfoById(compensationInfoId);
    }

    @RequestMapping("/saveOrUpdateDetail")
    @ResponseBody
    public Object saveOrUpdateDetail(Long caseInfoId, CompensationInfo entity) {
        compService.save(entity, caseInfoId);
        return new JsonResult();
    }

    //====================================================================

    //事故备案表
    @RequestMapping("/view")
    public String index() {
        return "compensate/caseInfo";
    }


    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAll() {
        return caseInfoService.listAll();
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object query(CaseInfoQuery qo) {
        return caseInfoService.query(qo);
    }




    //事故赔偿
    @RequestMapping("/viewPay")
    public String c() {
        return "compensate/pay";
    }
    // 只查询 等待付款
    @RequestMapping("/queryPay")
    @ResponseBody
    public Object queryPay(CaseInfoQuery qo) {
        qo.setStatus(Arrays.asList(CaseInfo.NOT_PAY));
        return caseInfoService.query(qo);
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(CaseInfo entity) {
        try {
            caseInfoService.saveOrUpdate(entity);
        } catch (Exception ex) {
            ex.printStackTrace();
            return new JsonResult().mark(ex.getMessage());
        }
        return new JsonResult();
    }
    // 验证案件
    @RequestMapping("/checkCase")
    @ResponseBody
    public Object checkCase(Long id) {
        caseInfoService.checkCase(id);
        return new JsonResult();
    }

    // 提审案件
    @RequestMapping("/needAudit")
    @ResponseBody
    public Object needAudit(Long id) {
        caseInfoService.needAudit(id);
        return new JsonResult();
    }

    // 废弃案件
    @RequestMapping("/crash")
    @ResponseBody
    public Object crash(Long id) {
        caseInfoService.crash(id);
        return new JsonResult();
    }

    // 拒审案件
    @RequestMapping("/cancelAudit")
    @ResponseBody
    public Object cancelAudit(Long id) {
        caseInfoService.cancelAudit(id);
        return new JsonResult();
    }
    // 审核案件
    @RequestMapping("/auditCase")
    @ResponseBody
    public Object auditCase(Long id) {
        caseInfoService.auditCase(id);
        return new JsonResult();
    }
    // 审核案件
    @RequestMapping("/payCase")
    @ResponseBody
    public Object payCase(Long id) {
        caseInfoService.payCase(id);
        return new JsonResult();
    }




//    @RequestMapping("delete")
//    @ResponseBody
//    public JsonResult delete(Long id) {
//        caseInfoService.delete(id);
//        return new JsonResult();
//    }

}
